package it.unina.lab.config;

import java.util.LinkedList;
import java.util.List;

import javax.management.RuntimeErrorException;

import com.continuent.tungsten.commons.patterns.fsm.Entity;
import com.continuent.tungsten.commons.patterns.fsm.Event;
import com.continuent.tungsten.commons.patterns.fsm.Guard;
import com.continuent.tungsten.commons.patterns.fsm.State;

import diuf.diva.hephaistk.xml.smuiml.Trigger;

public class TriggerParOrGuard implements Guard {

	private LinkedList<String> triggers_name;
	
	
	
	
	public TriggerParOrGuard(List<Trigger> triggers){
		triggers_name = new LinkedList<String>();
		for(Trigger trig : triggers){
			triggers_name.add(trig.getAttName().getValue());
			
		}
		
	}
	
	
	
	@Override
	public boolean accept(Event message, Entity entity, State state) {
		if (message.getData() instanceof String) {
			String evento = (String) message.getData();
			return(triggers_name.contains(evento));
				
		}
		else
			throw new RuntimeErrorException(new Error("Tipo di evento non stringa"));
		
	}

}
